<?php 
    //计算今天各活跃程度的顾客老顾客数量
	//设置时区
	ini_set('date.timezone','Asia/Shanghai');
    $conn = new mysqli("localhost:3306","root","lc971019");
	if($conn->connect_error)
	{
		die('Could not connect:'.$conn->connect_error());
	}
	
	//从上午8点开始计算
	$time_start = date("Y-m-d",intval(time()))." 08:00:00";
	//现在的时间
	$time_end = date("Y-m-d H:i:s",intval(time()));
	
	//高（一天内）
	$sql="select count(distinct wifidata.mac) from wifidata,ltc where (wifidata.times - ltc.times) <= 1000000 and wifidata.mac = ltc.mac and wifi.times > ".$time_start." and wifitimes < ".$time_end." and ranges < 200;";
	
	$result_AL_high = $conn->query($sql);
	
	$AL_high_count=0;//高活跃度人数
	
	if($result_AL_high->num_rows > 0){
		if($row = $result_AL_high->fetch_assoc()){
			$AL_high_count=$row["count(distinct wifidata.mac)"];
			}
		}
	//中	（一周内）
	$sql="select count(distinct wifidata.mac) from wifidata,ltc where (wifidata.times - ltc.times) <= 7*1000000 and wifidata.mac = ltc.mac and wifi.times > ".$time_start." and wifitimes < ".$time_end." and ranges < 200;";
	
	$result_AL_mid = $conn->query($sql);
	
	$AL_mid_count=0;//中活跃度人数
	
	if($result_AL_mid->num_rows > 0){
		if($row = $result_AL_mid->fetch_assoc()){
			$AL_mid_count=$row["count(distinct wifidata.mac)"];
			}
		}
	
	$AL_mid_count=$AL_mid_count-$AL_high_count;
	//低（一月内）
	$sql="select count(distinct wifidata.mac) from wifidata,ltc where (wifidata.times - ltc.times) <= 100000000 and wifidata.mac = ltc.mac and wifi.times > ".$time_start." and wifitimes < ".$time_end." and ranges < 200;";
	
	$result_AL_low = $conn->query($sql);
	
	$AL_low_count=0;//低活跃度人数
	
	if($result_AL_low->num_rows > 0){
		if($row = $result_AL_low->fetch_assoc()){
			$AL_low_count=$row["count(distinct wifidata.mac)"];
			}
		}
	
	$AL_low_count=$AL_low_count-$AL_mid_count-$AL_high_count;
	//沉睡
	$sql="select count(distinct wifidata.mac) from wifidata,ltc where (wifidata.times - ltc.times) > 100000000 and wifidata.mac = ltc.mac and wifi.times > ".$time_start." and wifitimes < ".$time_end." and ranges < 200;";
	
	$result_AL_sleep = $conn->query($sql);
	
	$AL_sleep_count=0;//沉睡活跃度人数
	
	if($result_AL_sleep->num_rows > 0){
		if($row = $result_AL_sleep->fetch_assoc()){
			$AL_sleep_count=$row["count(distinct wifidata.mac)"];
			}
		}
	
	
?>